// src/service/order/index.ts
import { http } from '@/utils/http'
import type { OrderInfoVo, OrderPageParams, OrderOperateDto, OrderStatusDto } from './order.d'
import { OrderStatusEnum } from './orderEnum.d'

// 状态映射
// 状态码与中文描述映射对象
export const OrderStatusMap = {
  [OrderStatusEnum.WAIT_PAY]: '待付款',
  [OrderStatusEnum.WAIT_DELIVER]: '待发货',
  [OrderStatusEnum.ALREADY_DELIVER]: '已发货',
  [OrderStatusEnum.WAIT_COMMENT]: '待评价',
  [OrderStatusEnum.COMPLETED]: '已完成',
  [OrderStatusEnum.REFUNDING]: '退款中',
  [OrderStatusEnum.RETURN_REFUND]: '退货退款中',
  [OrderStatusEnum.REFUNDED]: '退款完成',
  [OrderStatusEnum.CANCEL]: '已取消',
} as const
/** 订单服务API */
export const OrderApi = {
  /** 获取订单分页列表 */
  getPageList(params?: OrderPageParams) {
    return http<PageResult<OrderInfoVo>>({
      method: 'GET',
      url: '/order/info/list',
      query: params,
    })
  },

  /** 获取订单详情 */
  getDetail(id: number) {
    return http<OrderInfoVo>({
      method: 'GET',
      url: `/order/info/${id}`,
    })
  },

  /** 创建新订单 */
  createOrder(data: OrderOperateDto) {
    return http<string>({
      method: 'POST',
      url: '/order/info/add',
      data,
    })
  },

  /** 更新订单信息 */
  updateOrder(data: OrderInfoVo) {
    return http<boolean>({
      method: 'POST',
      url: '/order/info/update',
      data,
    })
  },

  /** 删除订单 */
  deleteOrder(id: number) {
    return http<boolean>({
      method: 'DELETE',
      url: `/order/info/delete/${id}`,
    })
  },

  /** 批量删除订单 */
  batchDelete(ids: number[]) {
    return http<boolean>({
      method: 'DELETE',
      url: '/order/info/delete/batch',
      query: { ids },
    })
  },
  /** 更新订单信息 */
  updateOrderStatus(data: OrderStatusDto) {
    return http<boolean>({
      method: 'POST',
      url: '/order/info/update/status',
      data,
    })
  },
}
